import instance from "@/request/request";
// 用户列表信息
export const userListApi = (
  params: IUserListParams
): RES<ITableResult<IProductModel>> => instance.get("/admin/list", { params });
// 修改用户状态
export const switchUserStatusApi = (id: number, status: number): RES<number> =>
  instance.post(`/admin/updateStatus/${id}?status=${status}`);

// 添加用户
export const addUserApi = (params: List): RES<List> =>
  instance.post("/admin/register", params);

// 拿到指定用户信息
export const getUserByIdApi = (id: number): RES<List> =>
  instance.get(`/admin/${id}`);

// 修改指定用户信息
export const editUserApi = (params: List): RES<number> =>
  instance.post(`/admin/update/${params.id}`, params);

export const getRoleListApi = (): RES<IRoleModel[]> =>
  instance.get("/role/listAll");
// 用户列表id
export const getRolesByUserIdApi = (adminId: number): RES<IRoleModel[]> =>
  instance.get(`/admin/role/${adminId}`);

// 更改角色
export const updateRolesUserApi = (id: number, roleId: number[]): RES<number> =>
  instance.post(`/admin/role/update?adminId=${id}&roleIds=${roleId.join(",")}`);

// 角色列表
export const roleListApi = (params: IUserListParams): RES<IRoleList> =>
  instance.get("role/list", { params });

// 修改用户角色状态
export const updateRoleStatusApi = (id: number, status: number): RES<number> =>
  instance.post(`/role/updateStatus/${id}?status=${status}`);

// 增加用户
export const addRoleApi = (params: RoleList): RES<RoleList> =>
  instance.post("/role/create", params);

// 获取角色相关资源
export const getResourceListApi = (roleId: number): RES<IResourceModel[]> =>
  instance.get(`role/listResource/${roleId}`);

// 查询所有后台资源
export const getAllResourceListApi = (): RES<IResourceModel[]> =>
  instance.get("/resource/listAll");

// 查询所有后台资源分类
export const resourceCategoryAllApi = (): RES<IResourceCategoryModel[]> =>
  instance.get("/resourceCategory/listAll");

// 分配资源
export const allocResourceApi = (params: allocResourcePramas) =>
  instance.post(
    `/role/allocResource?roleId=${params.roleId
    }&resourceIds=${params.resourceIds.join(",")}`
  );
// 获取菜单
export const treeListApi = (): RES<ItreeMenu[]> =>
  instance.get("/menu/treeList");

// /resource/list 分页模糊查询后台资源
export const resourceListApi = (
  params: IResourcePramas
): RES<IResourceListModel> => instance.get("/resource/list", { params });

// /menu/list/{parentId} 分页获取后台菜单
export const pagingGetMenuListApi = (
  parentId: number,
  params: any
): RES<IPagingMenuList> => instance.get(`/menu/list/${parentId}`, { params });
// /menu/updateHidden/{id} 修改后台菜单显示状态

export const updateRoleHiddenStatusApi = (
  id: number,
  hidden: number
): RES<number> => instance.post(`/menu/updateHidden/${id}?hidden=${hidden}`);

//  添加后台菜单 /menu/create
export const addMenuApi = (params: any): RES<object> =>
  instance.post("/menu/create", params);

// 修改后台菜单 /menu/update/{id}
export const updateMenuApi = (id: number, params: any): RES<object> =>
  instance.post(`/menu/update/${id}`, params);

//  根据id获取菜单详情 /menu/{id}
export const getMenuDataApi = (id: number): RES<IMenuData> =>
  instance.get(`/menu/${id}`);

// 分配菜单
export const roleListMenuApi = (roleId: number): RES<RoleListMenu[]> =>
  instance.get(`/role/listMenu/${roleId}`);
export const allocMenuApi = (paramas: allocResourcePramas) =>
  instance.post(
    `/role/allocMenu?roleId=${paramas.roleId
    }&menuIds=${paramas.resourceIds.join(",")}`
  );
